#!/usr/bin/env perl

use utf8;
use strict;
no warnings 'experimental::smartmatch';
use 5.010001;

say "Checking the number <$ARGV[0]>";

given($ARGV[0]){
	when (!/\A\d+\Z/){
		say "Not a number ..";
	}
	my $is_prime = divisors($_);

	when ($is_prime ~~ 1){
		say "Number is a prime";
	}
	default{
		say "Number is not a prime";
	}
}

sub divisors{
	my $number = shift;

	foreach my $divisor (2 .. $number / 2){
		unless($number % $divisor){
			return 0;
		}
	}

	return 1;
}